﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Jarvis.WCF.DataContracts;
using Jarvis.WCF.ServiceContracts;
using Action = Jarvis.WCF.DataContracts.Action;

namespace JarvisTestClient
{
    class Program
    {
        static void Main(string[] args)
        {
            var locatorService = GetProxyForLocationService();

            var locations = locatorService.GetKnownLocations();

            foreach (var location in locations)
            {
                Console.WriteLine(location.Name);
            }

            var new_location = new Location()
                               {
                                   Id= Guid.NewGuid(),
                                   Actions = new List<Action>(),
                                   Categories = new List<LocationCategory>(),
                                   Name = Guid.NewGuid().ToString()
                               };

            Console.WriteLine("Location ID: {0} Location Name: {1}",new_location.Id.ToString(),new_location.Name);
            locatorService.StoreLocation(new_location);

            Console.ReadKey();
        }

        public static ChannelFactory<ILocatorService> GetFactoryForLocationService()
        {

            return new DuplexChannelFactory<ILocatorService>(new WSDualHttpBinding("WSDualHttpBinding_ILocatorService"), "http://localhost:9090/Jarvis/Location");
        }

        public static ILocatorService GetProxyForLocationService()
        {

            return GetFactoryForLocationService().CreateChannel();
        }
    }    
}
